from .. import config as Config
from ..utils import Utils


def getMateialLibrary():
    file = Config.cachePath + "materialLibrary.json"
    data = Utils.read_json(file)
    dataDict = {}
    subKeys = ["id", "name", "density", "elasticity", "poisson", "shear"]
    for key, valueList in data.items():
        dataDict[key] = {}
        for i, value in enumerate(valueList):
            if value is not None and value != "":
                dataDict[key][subKeys[i]] = value
    return dataDict


def getStringedBarLibrary():
    file = Config.cachePath + "stringedBarLibrary.json"
    data = Utils.read_json(file)
    dataDict = {}
    subKeys = ["name", "type", "size"]
    for key, valueList in data.items():
        dataDict[key] = {}
        for i, value in enumerate(valueList):
            if i == 2 and value:
                # value = value.split(",")
                value = [float(item.strip()) for item in value.split(",")]
            if value is not None and value != "":
                if i == 2 and not value:
                    continue
                dataDict[key][subKeys[i]] = value
    return dataDict
